package com.tw.trips.ui;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Service;

import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.BaseTheme;

@Service
@Configurable(preConstruction = true)

public class Home extends HorizontalLayout {
	
	public GridLayout grid;
	
	public Home() {
		setSizeFull();
		Panel links = getLinksPanel();
		addComponent(links);
		Panel contents= getContentPane();
		addComponent(contents);
		Panel others = getOthersPanel();
		addComponent(others);
		
		
		
		/*setMargin(false);

		grid = new GridLayout(3, 1);
		grid.setSpacing(true);
		grid.setWidth("99%");
		grid.setHeight("99%");

		
		//Links Panel
		Panel links = getLinksPanel();
		grid.addComponent(links, 0,0);
		
		grid.setComponentAlignment(links, Alignment.MIDDLE_LEFT);
		
		//Main Content Panel
		VerticalLayout contentLayout = new VerticalLayout();
		contentLayout.setSizeFull();
		grid.addComponent(contentLayout,1,0);
		
		contentLayout.addComponent(getContentPane());
		
		
		//Others panel
		Panel othersPanel = getOthersPanel();
		grid.addComponent(othersPanel,2,0);
		grid.setComponentAlignment(othersPanel, Alignment.MIDDLE_RIGHT);
		

		addStyleName("border");
		setWidth("99%");
		setHeight("99%");
		
		addComponent(grid);*/

	}

	private Panel getOthersPanel() {
		Panel panel = new Panel();
		panel.setHeight("100%");
		panel.setWidth("25%");
		
		return panel;
	}

	private Panel getContentPane() {
		Panel panel = new Panel();
		panel.setHeight("100%");
		panel.setWidth("100%");
		
		return panel;
	}

	private Panel getLinksPanel() {
		Panel panel = new Panel();
		panel.setHeight("100%");
		panel.setWidth("25%");
		VerticalLayout vertLayout = (VerticalLayout) panel.getContent();
		
		
		Button trips = new Button("Trips");
		trips.setStyleName(BaseTheme.BUTTON_LINK);
		trips.setDescription("Lists your trips!");
		trips.addListener(new Button.ClickListener() {
			
			public void buttonClick(ClickEvent event) {
				// TODO Auto-generated method stub
				
			}
		}); 
		
		Button alerts = new Button("Alerts1");
		alerts.setStyleName(BaseTheme.BUTTON_LINK);
		alerts.setDescription("Alerts for your Trip!");
		alerts.addListener(new Button.ClickListener() {
			
			public void buttonClick(ClickEvent event) {
				// TODO Auto-generated method stub
				
			}
		}); 
		
		
		Button locations = new Button("Locations");
		locations.setStyleName(BaseTheme.BUTTON_LINK);
		locations.setDescription("Your Locations!");
		locations.addListener(new Button.ClickListener() {
			
			public void buttonClick(ClickEvent event) {
				// TODO Auto-generated method stub
				
			}
		}); 
		
		
		Button updates = new Button("Updates");
		updates.setStyleName(BaseTheme.BUTTON_LINK);
		updates.setDescription("Your Updates!");
		updates.addListener(new Button.ClickListener() {
			
			public void buttonClick(ClickEvent event) {
				System.out.println("Update Link Clicked");
				grid.removeComponent(1, 1);
				grid.addComponent(new UpdatePane(),1,1);
				
			}
		}); 
		
		
		vertLayout.addComponent(trips);
		vertLayout.setComponentAlignment(trips, Alignment.MIDDLE_LEFT);
		vertLayout.addComponent(alerts);
		vertLayout.setComponentAlignment(alerts, Alignment.MIDDLE_LEFT);
		vertLayout.addComponent(locations);
		vertLayout.setComponentAlignment(locations, Alignment.MIDDLE_LEFT);
		vertLayout.addComponent(updates);
		vertLayout.setComponentAlignment(updates, Alignment.MIDDLE_LEFT);
		
		
		return panel;
		
	}

	private Panel getHeader(String content, Alignment alignment) {
		Panel panel = new Panel();
		VerticalLayout vertLayout = (VerticalLayout) panel.getContent();
		Label label = new Label(content);
		panel.addComponent(label);

		vertLayout.addComponent(label);
		vertLayout.setComponentAlignment(label, alignment);
		return panel;
	}
}
